package com.asset.mapper;

import com.asset.pojo.Asset;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.additional.idlist.IdListMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

/**
 * @author 11725
 */
public interface AssetMapper extends Mapper<Asset>, IdListMapper<Asset, Long> {

    /**
     * 资产预定
     * @param record    Asset 对象
     * @return          受影响行数
     */
    @Update("UPDATE tab_asset SET status = #{status}, user_id = #{userId}, due_date = #{dueDate} "
            + "WHERE id = #{id} AND status = 0")
    int updateToReserveStatus(Asset record);

    /**
     * 查询可进行折旧的资产数据
     * @return          List
     */
    @Select("SELECT asset_id as id,asset_name as name,asset_number as number,asset_price as price,net_salvage,put_date,depr_completed_date as completed_date,depr_rate "
            + "FROM tab_asset WHERE status != 5 AND status != 7 "
            + "AND DATEDIFF(CURDATE(), put_date) >= 30 "
            + "AND DATEDIFF(CURDATE(), depr_completed_date) < 30;")
    List<Asset> selectByDepreciation();

    /**
     * 根据指定列进行分组计数
     * @param columnName        列名
     * @return                  计数集合
     */
    List<Map<String, String>> countByColumn(@Param("columnName") String columnName);

    /**
     * 根据分类进行分组统计
     * @return
     */
    List<Map<String, String>> countByCid();

    /**
     * 获取图表数据
     * @return
     */
    Integer selectCountTest();
}
